<template>
  <el-card>
    <el-form ref="formRef" :model="form" :rules="rules" label-width="100px" style="width:300px">
    
    <el-form-item label="用户名称" prop="username">
      <el-input v-model="form.username"></el-input>
    </el-form-item>
    <el-form-item label="用户密码" prop="password">
      <el-input v-model="form.password" disabled></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="submitForm">提交修改</el-button>
    </el-form-item>
  </el-form>
  </el-card>
</template>

<script setup>
import { ref } from 'vue';
import { useUserStore } from '@/stores/user'
const userStore = useUserStore()
console.log(userStore.user) 
    const formRef = ref(null);
    const form = ref({
      username: userStore.user.username,
      password: userStore.user.password,
    });

    const rules = ref({
      username: [
        { required: true, message: '请输入用户名称', trigger: 'blur' },
        { min: 2, max: 4, message: '名称长度在 2 到 4 个字符', trigger: 'blur' },
      ],
      password: [
        { required: true, message: '请输入密码', trigger: 'blur' },
        { min: 6, max: 12, message: '密码长度在 6 到 12 个字符', trigger: 'blur'}
      ],
    });

    const submitForm = () => {
      formRef.value.validate((valid) => {
        if (valid) {
          alert(`提交成功!${JSON.stringify(form.value)}`);
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    };

    

</script>
